package com.jinke.api.modules.ums.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jinke.api.modules.app.model.Order;
import com.jinke.api.modules.ums.mapper.ApiLogMapper;
import com.jinke.api.modules.ums.mapper.CancelApiLogMapper;
import com.jinke.api.modules.ums.model.ApiLog;
import com.jinke.api.modules.ums.model.CancelApiLog;
import com.jinke.api.modules.ums.model.Channel;
import com.jinke.api.modules.ums.service.IApiLogService;
import com.jinke.api.modules.ums.service.ICancelApiLogService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 取消
 * 订单取消日志表
 */
@Service
public class CancelApiLogServiceImpl extends ServiceImpl<CancelApiLogMapper, CancelApiLog> implements ICancelApiLogService {






    /**
     * 未执行的数据保存取消订单日志
     *
     * @param orderNumber 第三方的
     * @param orderNo     自己系统的
     * @param userId
     */
    @Override
    public void saveCancelApiLog(String orderNumber, String orderNo, Integer userId) {
        Thread thread = new Thread(() -> {

            CancelApiLog log=new CancelApiLog();
            log.setOrderNo(orderNo);
            log.setOrderNumber(orderNumber);
            log.setUserId(userId);
            save(log);
        });
        thread.start();
    }

    /**
     * 更新日志
     *
     * @param logs
     */
    @Override
    public void updateCancelApiLog(CancelApiLog log) {
        Thread thread = new Thread(() -> {
             updateById(log);
        });
        thread.start();
    }

    /**
     * 获取不超过三次待取消的失败的
     *
     * @return
     */
    @Override
    public List<CancelApiLog> getList() {


        LambdaQueryWrapper<CancelApiLog> queryWrapper = new LambdaQueryWrapper<CancelApiLog>()
                .eq(CancelApiLog::getIsSucesss, 0)
                .lt(CancelApiLog::getTryTime, 4);
        List<CancelApiLog> log = list(queryWrapper);
        

        return log;
    }
}
